package com.wanmait.schedule.controller;


import com.wanmait.schedule.entity.Schedule;
import com.wanmait.schedule.entity.Userinfo;
import com.wanmait.schedule.service.ScheduleService;
import com.wanmait.schedule.util.Result;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 * <p>
 * 日程表（备忘录表） 前端控制器
 * </p>
 *
 * @author wanmait
 * @since 2022-03-02
 */
@RestController
@RequestMapping("/Web/schedule")
public class ScheduleController {
    @Resource
    private ScheduleService scheduleService;
    //查询所有的日程的功能
    @GetMapping("listSchedule/{id}")
    public Result listSchedule(@PathVariable Integer id){
        /*System.out.println("//////////////////");
        System.out.println(id);*/
       return Result.success(scheduleService.findAll(id));
    }
    //后端添加日程功能
    @PostMapping("insertSchedule")
    private Result insertSchedule(@RequestBody Schedule schedule){
        System.out.println(schedule.getUserinfo());
        scheduleService.save(schedule);
        return Result.success("添加日程成功");
    }
    //后端删除日程功能
    @GetMapping("deleteSchedule")
    private Result deleteSchedule(Integer id){
     scheduleService.removeById(id);
     return Result.success("删除日程成功");
    }

     //通过日程id查询日程的相关信息
    @GetMapping("findById")
    public Result findById(Integer id){
        return Result.success(scheduleService.getById(id));
    }
    //修改日程的功能
    @PostMapping("updateScheule")
    public Result updateScheule(@RequestBody Schedule schedule){
        scheduleService.updateById(schedule);
        return Result.success("修改日志成功");
    }

}
